﻿using System;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

namespace Xejen.Database.Ef.MySql
{
    /// <summary>
    /// 表示适用于<see langword="MySql"/>的<see langword="Ef"/>框架的数据库上下文
    /// </summary>
    /// <creator>marc</creator>
    [DbConfigurationType(typeof(MySqlDbConfiguration))]
    public abstract class MySqlDbContext : EfDbContext
    {
        /// <inheritdoc cref="MySqlDbContext"/>
        /// <param name="connectionString">数据库连接字符串，如：Server=myserver;Database=mydatabase;User=myuser;Password=mypassword;</param>
        protected MySqlDbContext(string connectionString) : this(new MySqlConnection(connectionString))
        {
        }

        /// <inheritdoc cref="MySqlDbContext"/>
        /// <param name="existingConnection"><inheritdoc cref="EfDbContext.EfDbContext(DbConnection, bool)" path="/param[@name='existingConnection']"/></param>
        protected MySqlDbContext(DbConnection existingConnection) : this(existingConnection, true)
        {
        }

        /// <inheritdoc cref="MySqlDbContext"/>
        /// <param name="existingConnection"><inheritdoc cref="EfDbContext.EfDbContext(DbConnection, bool)" path="/param[@name='existingConnection']"/></param>
        /// <param name="contextOwnsConnection"><inheritdoc cref="EfDbContext.EfDbContext(DbConnection, bool)" path="/param[@name='contextOwnsConnection']"/></param>
        protected MySqlDbContext(DbConnection existingConnection, bool contextOwnsConnection) : base(existingConnection, contextOwnsConnection)
        {
        }

        /// <inheritdoc cref="MySqlDbContext"/>
        /// <param name="objectContext"><inheritdoc cref="EfDbContext.EfDbContext(ObjectContext, bool)" path="/param[@name='objectContext']"/></param>
        protected MySqlDbContext(ObjectContext objectContext) : this(objectContext, true)
        {
        }

        /// <inheritdoc cref="MySqlDbContext"/>
        /// <param name="objectContext"><inheritdoc cref="EfDbContext.EfDbContext(ObjectContext, bool)" path="/param[@name='objectContext']"/></param>
        /// <param name="dbContextOwnsObjectContext"><inheritdoc cref="EfDbContext.EfDbContext(ObjectContext, bool)" path="/param[@name='dbContextOwnsObjectContext']"/></param>
        protected MySqlDbContext(ObjectContext objectContext, bool dbContextOwnsObjectContext) : base(objectContext, dbContextOwnsObjectContext)
        {
        }

        /// <inheritdoc/>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            // Add MySQL specific configurations here if needed
        }
    }
}
